/*
 *
 * Copyright 2017-2018 549477611@qq.com(xiaoyu)
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, see <http://www.gnu.org/licenses/>.
 *
 */
package com.california.pay.common.utils;

import org.slf4j.Logger;

import java.util.Objects;
import java.util.function.Supplier;


/**
 */
public class LogUtil {


    /**
     * debug 打印日志
     *
     * @param logger   日志
     * @param format   日志信息
     * @param supplier supplier接口
     */
    public static <T> void debug(Logger logger, String format, Supplier<T> supplier) {
        if (logger.isDebugEnabled()) {
            logger.debug(format, supplier.get());
        }
    }

    public static <T> void debug(Logger logger, Supplier<T> supplier) {
        if (logger.isDebugEnabled()) {
            logger.debug(Objects.toString(supplier.get()));
        }
    }


    public static <T> void info(Logger logger, String format, Supplier<T> supplier) {
        if (logger.isInfoEnabled()) {
            logger.info(format, supplier.get());
        }
    }


    public static <T> void info(Logger logger, Supplier<T> supplier) {
        if (logger.isInfoEnabled()) {
            logger.info(Objects.toString(supplier.get()));
        }
    }


    public static <T> void error(Logger logger, String format, Supplier<T> supplier) {
        if (logger.isErrorEnabled()) {
            logger.error(format, supplier.get());
        }
    }

    public static <T> void error(Logger logger, Supplier<T> supplier) {
        if (logger.isErrorEnabled()) {
            logger.error(Objects.toString(supplier.get()));
        }
    }

    public static <T> void error(Logger logger, Throwable e, Supplier<T> supplier) {
        if (logger.isErrorEnabled()) {
            logger.error(Objects.toString(supplier.get()), e);
        }
    }

    public static void error(Logger logger, Throwable e, String errMsg) {
        if (logger.isErrorEnabled()) {
            logger.error(errMsg, e);
        }
    }

    public static <T> void warn(Logger logger, String format, Supplier<T> supplier) {
        if (logger.isWarnEnabled()) {
            logger.warn(format, supplier.get());
        }
    }

    public static <T> void warn(Logger logger, Supplier<T> supplier) {
        if (logger.isWarnEnabled()) {
            logger.warn(Objects.toString(supplier.get()));
        }
    }


    public static void info(Logger logger, String format, Object... arguments) {
        if (logger.isInfoEnabled()) {
            logger.info(format, arguments);
        }
    }

    public static void debug(Logger logger, String format, Object... arguments) {
        if (logger.isDebugEnabled()) {
            logger.debug(format, arguments);
        }
    }

    public static void warn(Logger logger, String format, Object... arguments) {
        if (logger.isWarnEnabled()) {
            logger.warn(format, arguments);
        }
    }

    public static void error(Logger logger, String format, Object... arguments) {
        if (logger.isErrorEnabled()) {
            logger.error(format, arguments);
        }
    }

}
